import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../ColorHelper.dart';
import '../log/LogUtil.dart';
import 'DialogUtil.dart';

class LoadingUtil {

  static bool _loadingFlag = false;

  static Future<void> loading({
        String? hint,
        bool canDismiss = true,
        bool canPop = true
      }) {
    _loadingFlag = true;
    return DialogUtil.dialog(
        Container(
          decoration: BoxDecoration(
              color: ColorHelper.white,
              borderRadius: BorderRadius.circular(10.r)),
          alignment: Alignment.center,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const CircularProgressIndicator(
                color: ColorHelper.teal_200,
              ),
              Offstage(
                offstage: hint == null,
                child: Padding(
                  padding: EdgeInsets.only(top: 8.h),
                  child: Text('$hint'),
                ),
              )
            ],
          ),
        ),
        canDismiss: canDismiss,
        canPop: canPop
    ).then((res){
      LogUtil.println(res);
      _loadingFlag = false;
    });
  }

  static void closeDialog(){
    if(_loadingFlag){
      Get.back();
    }
  }


}
